<template>
    <div class="app-container">
 
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="Plus"
            @click="openSelectUser"
           
            >更改菜单授权</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" plain icon="Close" @click="handleClose"
            >关闭</el-button
          >
        </el-col>
        <right-toolbar
          v-model:showSearch="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
  
      <el-table
        v-loading="loading"
        :data="userList"
  
      >
 
        <el-table-column
          label="菜单id"
          prop="id"
 
        />
  
        <el-table-column label="菜单名称" prop="description" :show-overflow-tooltip="true" />
  
        <el-table-column label="菜单路径" prop="path" :show-overflow-tooltip="true" />
        <el-table-column label="权限编码" prop="remark" :show-overflow-tooltip="true" />
  
 
 
      </el-table>
  
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
      <select-menu
        ref="selectRef"
        :roleId="queryParams.roleId"
        :menu="menuIds"
        @ok="handleQuery"
      />
    </div>
  </template>
  
  <script setup name="AuthUser">
  import selectMenu from "./selectMenu";
  import {
    listRoleMenu,
  } from "@/api/business/roleMenu";
 
 
  const route = useRoute();
  const { proxy } = getCurrentInstance();
  
  const userList = ref([]);
  const loading = ref(true);
  const showSearch = ref(true);

  const total = ref(0);
  const menuIds = ref([]);
  
  const queryParams = reactive({
    pageNum: 1,
    pageSize: 10,
    roleId: route.params.roleId,
  });
  
  /** 查询授权用户列表 */
  function getList() {
    loading.value = true;
    listRoleMenu(queryParams).then((response) => {
      menuIds.value = response.data.map(item => item.id )
      userList.value = response.data;
      loading.value = false;
    });
  }
  // 返回按钮
  function handleClose() {
    const obj = { path: "/system/role" };
    proxy.$tab.closeOpenPage(obj);
  }
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.pageNum = 1;
    getList();
  }
  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
  }
 
  /** 打开授权用户表弹窗 */
  function openSelectUser() {
    proxy.$refs["selectRef"].show();
  }
 
 
 
  
  getList();
  </script>
  